#include <cstdint>
#include <iostream>
#include <istream>
#include <map>
#include <vector>

using ll = int64_t;
using std::cin, std::cout;

const ll maxn = 1e5+5;
ll n, s[maxn];

std::map<ll, std::vector<ll>> hss;

int main(){
    std::iostream::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    cin>>n;
    for(ll i{1};i<=n;i++){
        cin>>s[i];
    }
    for(ll i{1};i<=n;i++){
        ll a;
        cin>>a;
        if(auto it {hss.find(s[i])}; it==hss.end()){
            hss.emplace(s[i], std::vector<ll>{a});
        }else{
            it->second.emplace_back(a);
        }
    }
    for(ll i{1};i<=n;i++){
        ll cnta{};
        ll maxs{};
        ll ni{i};
        auto nowm = hss.begin();
        auto nows = hss.begin()->second.begin();
        while(ni--){
            // cout<<"nows: "<<*nows<<'\n';
            cnta+=*nows;
            maxs = (*nowm).first;
            // cout<<"mxs: "<<maxs<<'\n';
            if((++nows)==(*nowm).second.end()){
                ++nowm;
                nows = nowm->second.begin();
            }
        }
        cout<<(maxs*2+cnta)<<'\n';
    }
}